package com.common.utils;

import java.net.InetAddress;

/**
 * @author xin.ding
 * @date 2021/3/18 20:50
 */
public class NetUtils {
    public static String convertHost(String host) {
        if (host.equals("127.0.0.1") || host.startsWith("localhost") || host.equals("0.0.0.0") || host.startsWith("169.254") || host.startsWith("::1") || host.startsWith("0:0:0:0:0:0:0:1")) {
            String localAddress;
            try {
                localAddress = InetAddress.getLocalHost().getHostAddress();
            } catch (Exception e) {
                localAddress = "localhost";
            }
            return localAddress;
        } else {
            return host;
        }
    }

}
